using MicroMsg.Common.Event;
using MicroMsg.Plugin.QQInfo.Manager;
using MicroMsg.Plugin.QQInfo.Scene;
using MicroMsg.Resource.@string;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Shell;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
namespace MicroMsg.UI.Page
{
	public class ViewQQSingleGroup : BasePage
	{
		private EventWatcher mOnGetQQFriendWatcher;
		private EventWatcher mWatcherHeadImgAdd;
		private NetSceneQQInfo mNetSceneQQInfo;
		private QGroup mQgroup;
		private uint mQGroupId;
		private bool isFromQQMsgPulgin;
		private CachedObservableCollection<QFriend, QQFriendsListItem> datas;
		private ApplicationBar mBar;
		internal Grid LayoutRoot;
		internal panelTitle2Line panelTitle;
		internal Grid ContentPanel;
		internal MMListBox FriendsList;
		private bool _contentLoaded;
		public ViewQQSingleGroup()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ViewQQSingleGroup_Loaded));
			base.set_ApplicationBar(this.GetApplicationBar());
		}
		private void ViewQQSingleGroup_Unloaded(object sender, RoutedEventArgs e)
		{
		}
		private void ViewQQSingleGroup_Loaded(object sender, RoutedEventArgs e)
		{
			this.loadData();
		}
		private void loadData()
		{
			if (this.mQgroup != null && this.datas == null)
			{
				List<QFriend> qQFriendList = QQInfoService.getInstance().GetQQFriendList(this.mQgroup.nGroupID, this.mQgroup.nMemberNum, ref this.mNetSceneQQInfo);
				if (qQFriendList != null)
				{
					this.datas = new CachedObservableCollection<QFriend, QQFriendsListItem>(qQFriendList.get_Count(), 100, 20, new FriendFetcher(this.mQGroupId, qQFriendList.get_Count()));
					if (this.datas != null)
					{
						this.datas.Bind(this.FriendsList);
						this.FriendsList.UpdateLayout();
						this.hideProgressCover();
					}
				}
				return;
			}
		}
		private void initEventWatcher()
		{
			this.mOnGetQQFriendWatcher = new EventWatcher(this, this, new EventHandlerDelegate(this.onEventHandlerGetQQFriend));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_QQFRIEND_ERR, this.mOnGetQQFriendWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_QQFRIEND_SUCCESS, this.mOnGetQQFriendWatcher);
			this.mWatcherHeadImgAdd = new EventWatcher(this, null, new EventHandlerDelegate(this.onEventHandlerHeadImgAdd));
			EventCenter.registerEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
		}
		private void unInitEventWatcher()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_QQFRIEND_ERR, this.mOnGetQQFriendWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_QQFRIEND_SUCCESS, this.mOnGetQQFriendWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_MGR_HEAD_IMG_READY, this.mWatcherHeadImgAdd);
			this.mOnGetQQFriendWatcher = null;
			this.mWatcherHeadImgAdd = null;
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (object_0 != null && Enumerable.Count<object>(object_0) != 0)
			{
				this.mQgroup = (object_0[0] as QGroup);
				this.mQGroupId = this.mQgroup.nGroupID;
				this.panelTitle.strSecondTitle = (string.IsNullOrEmpty(this.mQgroup.strGroupName) ? strings.QQFriend_Untitled : this.mQgroup.strGroupName);
				if (Enumerable.Count<object>(object_0) == 2 && object_0[1] != null)
				{
					string text = object_0[1] as string;
					if (text == "QQOfflineMsgPulgin")
					{
						this.isFromQQMsgPulgin = true;
					}
				}
			}
			QQFriendsListItem.isFromQQMsgPulgin = this.isFromQQMsgPulgin;
			this.showProgressCover(strings.QQFriend_GetInfo);
			this.initEventWatcher();
		}
		protected override void OnPageOut()
		{
			base.OnPageOut();
			this.unInitEventWatcher();
		}
		private void Friend_ListItem_ItemClick(object sender, object object_0)
		{
			QFriend qFriend = object_0 as QFriend;
			if (qFriend == null)
			{
				return;
			}
			object[] object_ = new object[]
			{
				qFriend
			};
			if (this.isFromQQMsgPulgin)
			{
				ChatContainerPage.GoToChatPage(this, qFriend.nQQ.ToString() + "@qqim", null, null, null);
				return;
			}
			if (qFriend.nWeixinStatus == 0u)
			{
				base.GoToPage("/Source/Plugin/ViewQQInfo/UI/QQFriendInfoWeixinOff.xaml", object_, false);
				return;
			}
			base.GoToPage("/Source/Plugin/ViewQQInfo/UI/QQFriendInfo.xaml", object_, false);
		}
		public void OnGetDataErrorHandler(DlgReturnEventArg dlgReturnEventArg_0)
		{
			switch (MMMessageBox.GetUserClickResult(dlgReturnEventArg_0))
			{
			case 0:
				this.showProgressCover(strings.QQFriend_GetInfo);
				QQInfoService.getInstance().GetQQFriendList(this.mQgroup.nGroupID, this.mQgroup.nMemberNum, ref this.mNetSceneQQInfo);
				return;
			case 1:
				base.GoBack();
				return;
			default:
				return;
			}
		}
		private void onEventHandlerGetQQFriend(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			this.hideProgressCover();
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_QQFRIEND_ERR)
			{
				MMMessageBox mMMessageBox = MMMessageBox.Show("", strings.QQFriend_GetInfo_Err, false, strings.COM_Retry, strings.COM_Return);
				mMMessageBox.ReturnEvent = new DlgReturnEvent(this.OnGetDataErrorHandler);
				return;
			}
			if (this.mQgroup.nMemberNum == 0)
			{
				MMMessageBox.Show("没有好友", true, "确定");
			}
			QFriendMgr.clearQQMemData();
			this.datas = new CachedObservableCollection<QFriend, QQFriendsListItem>(this.mQgroup.nMemberNum, 100, 20, new FriendFetcher(this.mQGroupId, this.mQgroup.nMemberNum));
			if (this.datas != null)
			{
				this.datas.Bind(this.FriendsList);
				this.FriendsList.UpdateLayout();
				return;
			}
			MMMessageBox mMMessageBox2 = MMMessageBox.Show("", strings.QQFriend_GetInfo_Err, false, strings.COM_Retry, strings.COM_Return);
			mMMessageBox2.ReturnEvent = new DlgReturnEvent(this.OnGetDataErrorHandler);
		}
		private void onEventHandlerHeadImgAdd(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			List<string> listObject = evtArgs.getListObject<string>();
			if (listObject == null)
			{
				return;
			}
			using (List<string>.Enumerator enumerator = listObject.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					string current = enumerator.get_Current();
					if (current != null && current.GetType() == typeof(string))
					{
						this._updateUserHead(current);
					}
				}
			}
		}
		private void _updateUserHead(string strUserName)
		{
			if (this.datas == null)
			{
				return;
			}
			ReadOnlyCollection<QFriend> currentDatas = this.datas.GetCurrentDatas();
			for (int i = 0; i < currentDatas.get_Count(); i++)
			{
				if (currentDatas.get_Item(i) != null)
				{
					string text = currentDatas.get_Item(i).nQQ.ToString() + "@qqim";
					if (text.CompareTo(strUserName) == 0)
					{
						this.datas[i] = this.datas[i];
						return;
					}
				}
			}
		}
		private void showProgressCover(string strCoverTitle)
		{
			ProcessingCover.getProgressBar(this.LayoutRoot, strCoverTitle, null, false, false, null);
		}
		private void hideProgressCover()
		{
			ProcessingCover.releaseProgressBar(this.LayoutRoot);
		}
		public IApplicationBar GetApplicationBar()
		{
			if (this.mBar != null)
			{
				return this.mBar;
			}
			this.mBar = new ApplicationBar();
			this.mBar.set_IsMenuEnabled(true);
			this.mBar.set_IsVisible(true);
			this.mBar.set_Opacity(0.7);
			ApplicationBarIconButton applicationBarIconButton = new ApplicationBarIconButton(new Uri("/Resource/Img/CommonUse/icon_search.png", 2));
			applicationBarIconButton.set_Text(strings.COM_Search);
			applicationBarIconButton.add_Click(new EventHandler(this.searchButton_Click));
			this.mBar.get_Buttons().Add(applicationBarIconButton);
			return this.mBar;
		}
		private void searchButton_Click(object sender, EventArgs e)
		{
			List<QFriend> sortedQFriendList = QFriendMgr.getSortedQFriendList((int)this.mQGroupId);
			List<SearchItem> list = new List<SearchItem>();
			int type = 7;
			if (sortedQFriendList != null)
			{
				using (List<QFriend>.Enumerator enumerator = sortedQFriendList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						QFriend current = enumerator.get_Current();
						if (current.strNickName != null)
						{
							list.Add(new SearchItem(current, this.getShowName(current), type, this.isFromQQMsgPulgin));
						}
					}
				}
			}
			SearchAlgorithm searchAlgorithm = new SearchAlgorithm(list);
			ToolFunction.GotoPageForUserControl("/Source/UI/ListSearchHelper/ListSearchPage.xaml", new object[]
			{
				searchAlgorithm
			}, false);
		}
		private string getShowName(QFriend qFriend)
		{
			string text;
			if (!string.IsNullOrEmpty(qFriend.strQQRemarkName))
			{
				text = qFriend.strQQRemarkName;
			}
			else
			{
				if (!string.IsNullOrEmpty(qFriend.strQQNickName))
				{
					text = qFriend.strQQNickName;
				}
				else
				{
					text = qFriend.nQQ.ToString();
				}
			}
			if (text != null)
			{
				text = text.Trim() + "\n" + qFriend.nQQ;
			}
			return text;
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/Plugin/Common/QQInfo/UI/ViewQQSingleGroupDetail.xaml", 2));
			this.LayoutRoot = (Grid)base.FindName("LayoutRoot");
			this.panelTitle = (panelTitle2Line)base.FindName("panelTitle");
			this.ContentPanel = (Grid)base.FindName("ContentPanel");
			this.FriendsList = (MMListBox)base.FindName("FriendsList");
		}
	}
}
